//
//  CZStatusViewModel.swift
//  WeiBo001
//
//  Created by ZhiQiang Li on 16/7/24.
//  Copyright © 2016年 ZhiQiang Li. All rights reserved.
//

import  UIKit

class CZStatusViewModel: NSObject {

    
    // 定义一个属性
    var status: HomeModel?
    // 微博认证用户图片
    var avatarImage: UIImage?
    //处理会员等级图片
    var memberImage: UIImage?

    
    // 重载构造函数
    init(status: HomeModel) {
        super.init()
        self.status = status
        self.avatarImage = getAvatarImage(status.user?.verified)
        self.memberImage = getMemberImage(status.user?.mbrank)
    }

        
    }

extension CZStatusViewModel {
    // 处理微博认证用户图片/// 认证类型 -1：没有认证，1，认证用户，2,3,5: 企业认证，220: 达人
    func getAvatarImage(verified: Int?) -> UIImage?{
        // 判读他是否为nil
        guard let ver = verified else{
            return nil
        }
        
        switch ver {
        case 1:
            return UIImage(named: "avatar_vip")
        case 2,3,5:
            return UIImage(named: "avatar_enterprise_vip")
        case 220:
            return UIImage(named: "avatar_grassroot")
        default:
            return UIImage(named: "avatar_vgirl")
        }
        
    }
    
    // 处理会员等级图片/// 会员等级 1-6
    func getMemberImage(mbrank: Int?) -> UIImage?{
        // 判断他是否为nil
        guard let mbr = mbrank else {
            return nil
        }
        if mbr > 0 && mbr < 7 {
            return UIImage(named: "common_icon_membership_level\(mbr)")
        }
        return UIImage(named: "common_icon_membership")
    }
}



